/**
 * Created by limei on 2018/6/12.
 */
import MYCONF from '../../myconf'
import mapHandler from './mapHandler'
import homeLayerHandler from './homeLayerHandler'

export default function mapInit(){
  minemap.accessToken = MYCONF.maps.token[MYCONF.maps.initStyle];
  minemap.solution = MYCONF.maps.solu[MYCONF.maps.initStyle];
  minemap.domainUrl = MYCONF.map.domain;
  minemap.dataDomainUrl = MYCONF.map.domain;
  this.map = new minemap.Map({
    container: 'map-container',
    style: MYCONF.maps.style[MYCONF.maps.initStyle],
    center: MYCONF.map.center,
    zoom: MYCONF.map.zoom,
    pitch: 0,
    // maxZoom: 17, //地图最大缩放级别限制
    maxZoom: 17, //地图全国视图-限制最大缩放级别
    minZoom: 3
  });

  this.map.repaint = true;

  this.handler = new mapHandler(this);

  this.map.on('load', () => {
    const map = this.map;
    let _this = this;
    _this.handler.loadImages();
    _this.handler.setMapEvent();
  });
  this.map.on('dragstart',() => {
    this.updateMapDraged(true);
  });
  this.map.on('move', () => {
    document.querySelector('.reset-icon-image').style.transform = `rotate(${this.map.getBearing()}deg)`;
  });
  this.map.on('zoomend', () => {
    const map = this.map;
   // console.log(map.getZoom());
    this.curZoom = Math.floor(map.getZoom());
  });

  window.map = this.map;
}

